﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using MyVoteMVC.Common.Extensions;

namespace MyVoteMVC.Common.Specifications
{
    internal class AndSpecification<TEntity> : ISpecification<TEntity> where TEntity : class
    {
        private ISpecification<TEntity> Spec1;
        private ISpecification<TEntity> Spec2;

        internal AndSpecification(ISpecification<TEntity> s1, ISpecification<TEntity> s2)
        {
            Spec1 = s1;
            Spec2 = s2;
        }

        public Expression<Func<TEntity, bool>> IsSatisfiedBy()
        {
            return Spec1.IsSatisfiedBy().Compose(Spec2.IsSatisfiedBy(), Expression.And);
        }
    }

}
